﻿/*   
  
   g10EXETryItCS -               Copyright (C) 2011 PH Informática, SA.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the  Free Software Foundation, either version 3 of the  License,  or
   (at your option) any later version.

   This  program  is distributed in  the hope that it will  be  useful,
   but  WITHOUT  ANY  WARRANTY; without even the  implied  warranty  of
   MERCHANTABILITY  or  FITNESS  FOR  A  PARTICULAR  PURPOSE.  See  the
   GNU General Public License for more details.

   You  should have received  a copy of  the GNU General Public License
   along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;

public static class csModule
{

    // TokenID de utilização do serviço
    public static string sApiTokenID = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee";
     
    // SessionID identificação da sessão, deve ser gerado de cada vez que uma nova sessão
    // se inicia ou sempre que se achar necessário.
    public static string sSessionID = System.Guid.NewGuid().ToString();

    // Ligação ao webService
    public static g10EXETryItCS.g10WSTryIt.g10TryItSoapClient myWs = new g10EXETryItCS.g10WSTryIt.g10TryItSoapClient();

    // ActualView
    public static g10EXETryItCS.g10WSTryIt.g10MapView oActualView;

    public static bool bLoading = false;
    // Função que retorna imagem do mapa
    public static System.Drawing.Image GetMapa(double dCentroX, double dCentroY, long lEscala, long lImageWidth, long lImageHeight)
	{

		bLoading = true;

		System.Drawing.Image oImage = null;
		byte[] bImageMapa = null;
		System.IO.MemoryStream oMemStream = null;


		try {
			// Invicação do método do webService
			bImageMapa = myWs.GetMapa(sApiTokenID, sSessionID, dCentroX, dCentroY, lEscala, lImageWidth, lImageHeight, false);

			// Tranformação do array de bytes em Imagem
			oMemStream = new System.IO.MemoryStream(bImageMapa, 0, bImageMapa.Length);
			oMemStream.Write(bImageMapa, 0, bImageMapa.Length);
			oImage = System.Drawing.Image.FromStream(oMemStream, true);

			oActualView = myWs.getActualView(sApiTokenID, sSessionID);

			return oImage;


		} catch (Exception ex) {
			//MsgBox(ex.ToString(), , "Aviso! Algo não correu muito bem...");
			return null;


		} finally {
			bLoading = false;

		}

	}

    public class ListItem
    {
        private string _name;
        private string _key;

        public ListItem(string p_name, string p_key)
        {
            _name = p_name;
            _key = p_key;
        }

        public string Key()
        {
            return _key;
        }

        public string Name()
        {
            return _name;
        }

        public override string ToString()
        {
            return _name;
        }

    }

}
